package admin

import (
	"mxshop/app/mxshop_api/admin/config"
	"mxshop/app/mxshop_api/admin/internal/controller"
	"mxshop/app/mxshop_api/admin/internal/data/rpc"
	"mxshop/app/mxshop_api/admin/internal/service"
	"mxshop/app/mxshop_api/api/pkg/auth/JWTAuth"
	"mxshop/gmicro/server/restserver"
)

func initRouter(g *restserver.Server, cfg *config.Config) {
	v1 := g.Group("/v1")
	userGroup := v1.Group("/user")

	data, err := rpc.GetDataFactoryOr(cfg.Registry)
	if err != nil {
		panic(err)
	}
	serviceFactory := service.NewService(data)

	// jwt 验证中间件
	_ = JWTAuth.NewJWTAuth(cfg.Jwt) // 做 jwt 校验用

	// 用户相关接口
	uController := controller.NewUserController(g.Translator(), serviceFactory)
	{
		userGroup.GET("list", uController.List)
	}
}
